using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//using System.Numeric;

namespace pardusshipcalc
{
    public partial class GunSetupAdvisor : Form
    {
        // Set up instances of custom classes.
        Ship playerShip = new Ship();
        Guns gunClass = new Guns();

        string shipName;
        int spaceRem;
        int OWEAPSPEC = -1;
        int EMWEAPSPEC = -1;
        int CONVWEAPSPEC = -1;
        int TANK_SIZE = 0;
        public GunSetupAdvisor(string NAME, int SPACEREM, int oWeapSpec, int emWeapSpec, int convWeapSpec, int tankSize)
        {
            InitializeComponent();
            shipName = NAME;
            spaceRem = SPACEREM;

            OWEAPSPEC = oWeapSpec;
            EMWEAPSPEC = emWeapSpec;
            CONVWEAPSPEC = convWeapSpec;
            TANK_SIZE = tankSize;
        }

        int MAX_HULLCAP = 0;
        //int LIMIT_HULLCAP = 0;
        int GUN_MOUNTS = 0;
        int MISSILE_MOUNTS = 0;
        int modeGunSlots = 1;
        int modeHullCap = 2;
        int modeMissileMounts = 0;
        int modeGunDamage = 0;
        int modeGunFireRate = 1;
        int modeGunWeight = 2;

        private int useExactAlgorithm()
        {
            int hullCap = (int)spaceLimiterUpDown.Value;

            // 1. Set up bools:
            bool excludeOrganicWeapons = false;
            bool excludeEMWeapons = false;
            bool excludeConvWeapons = false;
            bool excludePardusWeapons = false;
            bool excludeEmpGear = false;

            // 2. Check for user-selected logic:
            #region assignBools
            if (excludeOWCheckBox.Checked == true)
            {
                excludeOrganicWeapons = true;
            }
            if (excludeEMWCheckBox.Checked == true)
            {
                excludeEMWeapons = true;
            }
            if (excludeCWCheckBox.Checked == true)
            {
                excludeConvWeapons = true;
            }
            if (excludePWCheckBox.Checked == true)
            {
                excludePardusWeapons = true;
            }
            if (excludeEmpCheckBox.Checked == true)
            {
                excludeEmpGear = true;
            }
            #endregion



            CombinationLauncher permLaunch = new CombinationLauncher(hullCap, GUN_MOUNTS, int.Parse(multiplierComboBox.Text), enemyArmorComboBox.SelectedIndex, excludeOrganicWeapons, excludeEMWeapons, excludeConvWeapons, excludePardusWeapons, excludeEmpGear, OWEAPSPEC, EMWEAPSPEC, CONVWEAPSPEC);
                permLaunch.ShowDialog();
               // MessageBox.Show(string.Format("{0} : {1} : {2} : {3} : {4} : {5} : {6}", permLaunch.ExactAlgoResult[0], permLaunch.ExactAlgoResult[1], permLaunch.ExactAlgoResult[2], permLaunch.ExactAlgoResult[3], permLaunch.ExactAlgoResult[4], permLaunch.ExactAlgoResult[5], permLaunch.ExactAlgoResult[6]));
                if (permLaunch.ExactAlgoResult != null)
                {
                    updateFormForExactAlgorithm(permLaunch.ExactAlgoResult);
                }

            return 0;
        }

        private void updateFormForExactAlgorithm(int[] returnData)
        {
            int i;
            int modeDamage = 0;
            int modeFireRate = 1;
            int modeWeight = 2;
            double[] GunEfficiency = { 0, 0, 0, 0, 0 };
            int[] GunTypes = { 0, 0, 0, 0, 0 };
            string[] GunNames = { "", "", "", "", "" };
            double[] GunDamages = { 0, 0, 0, 0, 0 };
            double[] EffGunDamages = { 0, 0, 0, 0, 0 };
            int[] GunFireRates = { 0, 0, 0, 0, 0 };
            int[] GunWeights = { 0, 0, 0, 0, 0, };
            double[] effVsC = { 0, 0, 0, 0, 0 };
            double[] effVsO = { 0, 0, 0, 0, 0 };
            double[] effVsEM = { 0, 0, 0, 0, 0 };
            double[] effVsP = { 0, 0, 0, 0, 0 };
            double[] effVsExotAVG = { 0, 0, 0, 0, 0 };
            double[] effVsCOEM_AVG = { 0, 0, 0, 0, 0 };
            double[] effVsAll_AVG = { 0, 0, 0, 0, 0 };
            double armorStrength = double.Parse(multiplierComboBox.Text);

            for (i = 0; i < GUN_MOUNTS; i++)
            {
                GunTypes[i] = gunClass.determineGunType(returnData[i]);
                GunNames[i] = gunClass.determineGunName(returnData[i]);
                GunEfficiency[i] = gunClass.determineGunEfficiency(GunTypes[i], false, 0, enemyArmorComboBox);
                GunFireRates[i] = gunClass.GetGunData(ref modeFireRate, GunNames[i]);
                GunWeights[i] = gunClass.GetGunData(ref modeWeight, GunNames[i]);
                GunDamages[i] = ((gunClass.GetGunData(ref modeDamage, GunNames[i])) * GunFireRates[i]);
                GunDamages[i] = Math.Round(gunClass.determineGunDamageWithWeapSpec(GunDamages[i], GunTypes[i], CONVWEAPSPEC, OWEAPSPEC, EMWEAPSPEC));
                EffGunDamages[i] = Math.Round(((GunDamages[i] / 100) * GunEfficiency[i]) / armorStrength );
                //MessageBox.Show(GunTypes[0] + " " + GunEfficiency[0] + " " + armorStrength);
            }
            for (i = 0; i < GUN_MOUNTS; i++)
            {
                effVsC[i] = ((((GunDamages[i])) / 100) * (gunClass.determineGunEfficiency((GunTypes[i]), true, 0, enemyArmorComboBox)) / armorStrength);
                effVsO[i] = ((((GunDamages[i])) / 100) * (gunClass.determineGunEfficiency((GunTypes[i]), true, 1, enemyArmorComboBox)) / armorStrength);
                effVsEM[i] = ((((GunDamages[i])) / 100) * (gunClass.determineGunEfficiency((GunTypes[i]), true, 2, enemyArmorComboBox)) / armorStrength);
                effVsP[i] = ((((GunDamages[i])) / 100) * (gunClass.determineGunEfficiency((GunTypes[i]), true, 3, enemyArmorComboBox)) / armorStrength);
                effVsCOEM_AVG[i] = (effVsC[i] + effVsO[i] + effVsEM[i]) / 3;
                effVsExotAVG[i] = (effVsO[i] + effVsEM[i]) / 2;
                effVsAll_AVG[i] = (effVsC[i] + effVsO[i] + effVsEM[i] + effVsP[i]) / 4;
            }
            for (i = 0; i < GUN_MOUNTS; i++)
            {
                try
                {
                    
                    weaponDataGrid.Rows[i].Cells[0].Value = (i + 1);
                    weaponDataGrid.Rows[i].Cells[1].Value = GunNames[i];
                    weaponDataGrid.Rows[i].Cells[2].Value = GunDamages[i];// Needs to multiply by fire rate.                    
                    weaponDataGrid.Rows[i].Cells[3].Value = EffGunDamages[i];
                    weaponDataGrid.Rows[i].Cells[4].Value = GunEfficiency[i] + "%";
                    weaponDataGrid.Rows[i].Cells[5].Value = GunWeights[i];
                    weaponDataGrid.Rows[i].Cells[6].Value = effVsC[i];
                    weaponDataGrid.Rows[i].Cells[7].Value = effVsO[i];
                    weaponDataGrid.Rows[i].Cells[8].Value = effVsEM[i];
                    weaponDataGrid.Rows[i].Cells[9].Value = effVsP[i];
                    weaponDataGrid.Rows[i].Cells[10].Value = effVsCOEM_AVG[i];
                    weaponDataGrid.Rows[i].Cells[11].Value = effVsExotAVG[i];
                    weaponDataGrid.Rows[i].Cells[12].Value = effVsAll_AVG[i];
                }
                catch (Exception)
                {
                    MessageBox.Show("Error Updating Data Grid");
                }
            }
            totalEffDamageLabel.Text = "Total Effective Damage: " + (EffGunDamages[0] + EffGunDamages[1] + EffGunDamages[2] + EffGunDamages[3] + EffGunDamages[4]).ToString();
            averageEffLabel.Text = "Average Efficiency: " + ((GunEfficiency[0] + GunEfficiency[1] + GunEfficiency[2] + GunEfficiency[3] + GunEfficiency[4]) / GUN_MOUNTS).ToString();
            totalWeightLabel.Text = "Weight: " + (GunWeights[0] + GunWeights[1] + GunWeights[2] + GunWeights[3] + GunWeights[4]).ToString();
            totalbaseDamageLabel.Text = "Total Base Damage: " + (GunDamages[0] + GunDamages[1] + GunDamages[2] + GunDamages[3] + GunDamages[4]).ToString();

        }

        private int useApproximateAlgorithm()
        {

            // Work out maximum damage setup.
            // 1. Set up bools:
            bool excludeOrganicWeapons = false;
            bool excludeEMWeapons = false;
            bool excludeConvWeapons = false;
            bool excludePardusWeapons = false;
            bool excludeEmpGear = false;

            double[] damage = { 0, 0, 0, 0, 0 };
            double[] basedamage = { 0, 0, 0, 0, 0 };
            int[] type = { 0, 0, 0, 0, 0 };
            string[] gunName = { "", "", "", "", "" };
            string[] MaxgunName = { "", "", "", "", "" };
            double[] gunefficiency = { 0, 0, 0, 0, 0 };
            int[] weight = { 0, 0, 0, 0, 0 };
            int[] finalGunType = { 0, 0, 0, 0, 0 };
            int maxDamage = 0;
            double tempDamage = 0;
            double efficiency = 0;
            double armorStrength = 0;
            int[,] gunData = gunClass.GunData;
            bool typeConflict = false;
            int spaceUsed = 0;
            int hullToUse = (int) spaceLimiterUpDown.Value;
            double[] effVsC = { 0, 0, 0, 0, 0 };
            double[] effVsO = { 0, 0, 0, 0, 0 };
            double[] effVsEM = { 0, 0, 0, 0, 0 };
            double[] effVsP = { 0, 0, 0, 0, 0 };
            double[] effVsExotAVG = { 0, 0, 0, 0, 0 };
            double[] effVsCOEM_AVG = { 0, 0, 0, 0, 0 };
            double[] effVsAll_AVG = { 0, 0, 0, 0, 0 };

            // indexes
            int i, j, k;
            int gunNumber;

            // 2. Check for user-selected logic:
            #region assignBools
            if (excludeOWCheckBox.Checked == true)
            {
                excludeOrganicWeapons = true;
            }
            if (excludeEMWCheckBox.Checked == true)
            {
                excludeEMWeapons = true;
            }
            if (excludeCWCheckBox.Checked == true)
            {
                excludeConvWeapons = true;
            }
            if (excludePWCheckBox.Checked == true)
            {
                excludePardusWeapons = true;
            }
            if (excludeEmpCheckBox.Checked == true)
            {
                excludeEmpGear = true;
            }
            #endregion


            //4. Find the highest possible Gun Damage Output.

            // Work out armor strength:
            try
            {
                armorStrength = (double.Parse(multiplierComboBox.Text));
            }
            catch
            {
            }

            // Get first gun, compare it to  all other guns  in slots 2-5.
            for (i = 0; i < GUN_MOUNTS; i++)
            {
                for (k = 0; k < 37; k++)
                {
                    // State which gun we're using.
                    gunNumber = i;

                    // Determine its type:
                    type[gunNumber] = gunClass.determineGunType(k);
                    typeConflict = false;

                    // Check other guns for type conflict.
                                      

                    // Determine gun efficiency:
                    efficiency = gunClass.determineGunEfficiency(type[gunNumber], false, 0, enemyArmorComboBox);

                    // Work out roughly the damage done:
                    tempDamage = ((gunData[k, modeGunDamage]) * (gunData[k, modeGunFireRate]));
                    tempDamage = gunClass.determineGunDamageWithWeapSpec(tempDamage, type[gunNumber], CONVWEAPSPEC, OWEAPSPEC, EMWEAPSPEC);
                    tempDamage = (((tempDamage / 100) * efficiency) / armorStrength);

                    // Work out max damage:
                    if ((((spaceUsed - weight[gunNumber]) + gunData[k, modeGunWeight]) <= (hullToUse)) && ((gunData[k, modeGunWeight] <= ((hullToUse / GUN_MOUNTS) * 1.05))) && (damage[gunNumber] <= tempDamage) && (typeConflict == false))
                    {
                        if (((excludeEmpGear == true) && ((k > 11) && (k < 25))) || ((excludeOrganicWeapons == true) && ((k >= 25) && (k < 29))) || ((excludeEMWeapons == true) && ((k >= 29) && (k < 33))) || ((excludePardusWeapons == true) && ((k >= 33))) || ((excludeConvWeapons == true) && ((k >= 0) && (k < 25))))
                        {
                        }
                        else
                        {
                            // The last best damage output for this gun was not as good as the current one, so make it the chosen one.

                            gunName[gunNumber] = determineGunName(k);
                            weight[gunNumber] = gunData[k, modeGunWeight];
                            damage[gunNumber] = tempDamage;
                            spaceUsed = weight[0] + weight[1] + weight[2] + weight[3] + weight[4];
                            basedamage[gunNumber] = ((gunData[k, modeGunDamage]) * (gunData[k, modeGunFireRate]));
                            gunefficiency[gunNumber] = efficiency;
                            finalGunType[gunNumber] = type[gunNumber];
                        }
                    }
                }
                if ((damage[0] + damage[1] + damage[2] + damage[3] + damage[4]) > maxDamage)
                {
                    maxDamage = (int)(damage[0] + damage[1] + damage[2] + damage[3] + damage[4]);
                    for (j = 0; j < gunName.Length; j++)
                    {
                        MaxgunName[j] = gunName[j];
                    }
                }
            }

            // Work out Averages:
            for (i = 0; i < GUN_MOUNTS; i++)
            {
                effVsC[i] = ((((basedamage[i])) / 100) * (gunClass.determineGunEfficiency((gunClass.determineGunType(finalGunType[i])), true, 0, enemyArmorComboBox)) / armorStrength);
                effVsO[i] = ((((basedamage[i])) / 100) * (gunClass.determineGunEfficiency((gunClass.determineGunType(finalGunType[i])), true, 1, enemyArmorComboBox)) / armorStrength);
                effVsEM[i] = ((((basedamage[i])) / 100) * (gunClass.determineGunEfficiency((gunClass.determineGunType(finalGunType[i])), true, 2, enemyArmorComboBox)) / armorStrength);
                effVsP[i] = ((((basedamage[i])) / 100) * (gunClass.determineGunEfficiency((gunClass.determineGunType(finalGunType[i])), true, 3, enemyArmorComboBox)) / armorStrength);
                effVsCOEM_AVG[i] = (effVsC[i] + effVsO[i] + effVsEM[i]) / 3;
                effVsExotAVG[i] = (effVsO[i] + effVsEM[i]) / 2;
                effVsAll_AVG[i] = (effVsC[i] + effVsO[i] + effVsEM[i] + effVsP[i]) / 4;
            }
            // Update the Datagrid
            for (i = 0; i < GUN_MOUNTS; i++)
            {
                try
                {
                    weaponDataGrid.Rows[i].Cells[0].Value = (i + 1);
                    weaponDataGrid.Rows[i].Cells[1].Value = MaxgunName[i];
                    weaponDataGrid.Rows[i].Cells[2].Value = basedamage[i];
                    weaponDataGrid.Rows[i].Cells[3].Value = damage[i];
                    weaponDataGrid.Rows[i].Cells[4].Value = gunefficiency[i] + "%";
                    weaponDataGrid.Rows[i].Cells[5].Value = weight[i];
                    weaponDataGrid.Rows[i].Cells[6].Value = effVsC[i];
                    weaponDataGrid.Rows[i].Cells[7].Value = effVsO[i];
                    weaponDataGrid.Rows[i].Cells[8].Value = effVsEM[i];
                    weaponDataGrid.Rows[i].Cells[9].Value = effVsP[i];
                    weaponDataGrid.Rows[i].Cells[10].Value = effVsCOEM_AVG[i];
                    weaponDataGrid.Rows[i].Cells[11].Value = effVsExotAVG[i];
                    weaponDataGrid.Rows[i].Cells[12].Value = effVsAll_AVG[i];
                }
                catch (Exception)
                {
                    MessageBox.Show("Error Updating Data Grid");
                }
            }
            totalEffDamageLabel.Text = "Total Effective Damage: " + (damage[0] + damage[1] + damage[2] + damage[3] + damage[4]).ToString();
            averageEffLabel.Text = "Average Efficiency: " + ((gunefficiency[0] + gunefficiency[1] + gunefficiency[2] + gunefficiency[3] + gunefficiency[4]) / GUN_MOUNTS).ToString();
            totalWeightLabel.Text = "Weight: " + (weight[0] + weight[1] + weight[2] + weight[3] + weight[4]).ToString();
            totalbaseDamageLabel.Text = "Total Base Damage: " + (basedamage[0] + basedamage[1] + basedamage[2] + basedamage[3] + basedamage[4]).ToString();

            return maxDamage;
        }

        public bool DetectTypeConflict(int[] type, int gunNumber)
        {
            bool conflict = false;
            int l;

            for (l = 0; l < 5; l++)
                    {
                        if (l != gunNumber)
                        {
                            if (type[l] == 1)
                            {
                                if (type[gunNumber] == 2)
                                {
                                    conflict = true;
                                }
                            }
                            if (type[l] == 2)
                            {
                                if (type[gunNumber] == 1)
                                {
                                    conflict = true;
                                }
                            }
                        }
                    }
            return conflict;
        }

        private string determineGunName(int gunNumber)
        {
            string gunName = "";

            switch (gunNumber)
            {
                case 0:
                gunName = "None";
                break;

                case 1:
                    gunName = "10MW Mining Laser";
                break;

                case 2:
                    gunName = "30MW Mining Laser";
                  break;

                case 3:
                    gunName = "1MW Impulse Laser";
                    break;

                case 4:
                    gunName = "5MW Impulse Laser";
                    break;

                case 5:
                    gunName = "1MW Particle Laser";
                    break;

                case 6:
                    gunName = "4MW Particle Laser";
                    break;

                case 7:
                    gunName = "4MW LW Particle Laser";
                    break;

                case 8:
                    gunName = "20MW Particle Laser";
                    break;

                case 9:
                    gunName = "20MW LW Particle Laser";
                    break;

                case 10:
                    gunName = "100MW Particle Laser";
                    break;

                case 11:
                    gunName = "100MW LW Particle Laser";
                    break;

                case 12:
                    gunName = "4MW Gatling Laser";
                    break;

                case 13:
                    gunName = "4MW LW Gatling Laser";
                    break;

                case 14:
                    gunName = "6MW Gatling Laser";
                    break;

                case 15:
                    gunName = "6MW LW Gatling Laser";
                    break;

                case 16:
                  gunName = "10MW Gatling Laser";
                    break;

                case 17:
                    gunName = "10MW LW Gatling Laser";
                    break;

                case 18:
                    gunName = "20MW Gatling Laser";
                    break;

                case 19: gunName = "20MW LW Gatling Laser"; break;

                case 20: gunName = "35MW Plasma"; break;

                case 21: gunName = "40MW Plasma"; break;

                case 22: gunName =  "60MW Plasma"; break;

                case 23: gunName = "140MW Particle Laser"; break;

                case 24: gunName = "140MW LW Particle Laser"; break;

                case 25: gunName = "Exoplasm Launcher"; break;

                case 26: gunName = "Endoplasm Launcher"; break;

                case 27: gunName = "Bio-Spore Array"; break;

                case 28: gunName = "Viral Glands";break;

                case 29: gunName = "80MT Magnetic Defractor"; break;

                case 30: gunName = "120MT Magnetic Defractor"; break;

                case 31: gunName = "Large Pulse Cannon"; break;
                
                case 32: gunName = "Very Large Pulse Cannon"; break;
                
                case 33: gunName = "Lucidi Enforcer I"; break;

                case 34: gunName = "Lucidi Enforcer II"; break;

                case 35: gunName = "Lucidi Conqueror"; break;

                case 36: gunName = "Lucidi Plasma Thrower"; break;
            }
            return gunName;
        }

        private string determineMissileName(int missileNumber)
        {
            // Convert missile index numbers into missile name strings.
            string missileName = "";

            switch (missileNumber)
            {
                case 0:
                    missileName = "P80 Sidewinder";
                    break;

                case 1:
                    missileName = "KL760 Homing";
                    break;

                case 2:
                    missileName = "LV111 Intelligent";
                    break;

                case 3:
                    missileName = "NN500";
                    break;

                case 4:
                    missileName = "NN550";
                    break;

                case 5:
                    missileName = "MO89 Lord";
                    break;

                case 6:
                    missileName = "G-7 Smartwinder";
                    break;

                case 7:
                    missileName = "A/50 Pogo";
                    break;

                case 8:
                    missileName = "D/70 Havar";
                    break;

                case 9:
                    missileName = "Elite Mk.I";
                    break;

                case 10:
                    missileName = "Elite Mk.II";
                    break;

                case 11:
                    missileName = "King Relon";
                    break;

                case 12:
                    missileName = "King Kraak";
                    break;

                case 13:
                    missileName = "Royal Redeemer";
                    break;
            }

            return missileName;
        }
        
        private void MaxDamageForm_Load(object sender, EventArgs e)
        {            
            enemyArmorComboBox.Text = "Conventional";
            multiplierComboBox.Text = "1";
            GUN_MOUNTS = playerShip.GetShipData(ref modeGunSlots, shipName);
            MISSILE_MOUNTS = playerShip.GetShipData(ref modeMissileMounts, shipName);
            MAX_HULLCAP = playerShip.GetShipData(ref modeHullCap, shipName);
            maxHullCapLabel.Text = "/" + MAX_HULLCAP.ToString();
            spaceLimiterUpDown.Maximum = MAX_HULLCAP;

            // Add number of rows to dataGrid
            if (GUN_MOUNTS > 0)
            {
                weaponDataGrid.Rows.Add(GUN_MOUNTS);
            }

            if ((shipName != "- Ficon") && (shipName != "- Tyrant") && (shipName != "- Spectre") && (shipName != "- Shadow Stealth Craft") && (shipName != "- Venom") && (shipName != "- Constrictor") && (shipName != "- Phantom Advanced Stealth Craft") && (shipName != "- Dominator") && (shipName != "- Boa Ultimate Carrier") && (shipName != "- Mooncrusher") && (shipName != "- Sabre") &&
(shipName !="- Rustclaw") && (shipName !="- Interceptor") && (shipName !="- Lanner Mini") && (shipName !="- Harrier") && (shipName !="- Mercury") && (shipName !="- Hercules") && (shipName !="- Lanner") && (shipName !="- Hawk") && (shipName !="- Gargantua") && (shipName !="- Behemoth") && (shipName !="- Liberator") && (shipName !="- Leviathan"))
            {
                excludeEmpCheckBox.Checked = true;
                excludeEmpCheckBox.Enabled = false;
                designerShipCheckBox.Checked = false;
            }
            designerShipCheckBox.Checked = true;
            useApproximateAlgorithm();
        }

        private void enemyArmorComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ((enemyArmorComboBox.Text == "Organic") || (enemyArmorComboBox.Text == "Electro-Magnetic"))
            {
                multiplierComboBox.Items.Remove("1");
                multiplierComboBox.Items.Remove("6");
            }
            else
            {
                if (multiplierComboBox.Items.Contains("6") != true)
                {
                    multiplierComboBox.Items.Add("6");
                }
                if (multiplierComboBox.Items.Contains("1") != true)
                {
                    multiplierComboBox.Items.Add("1");
                }
                // Make sure items are in correct order when put back into the combo.
                multiplierComboBox.Sorted = true;
            }
            if (multiplierComboBox.SelectedIndex == -1)
            {
                multiplierComboBox.SelectedIndex = 0;
            }
        }

        private void useExactAlgorithmCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            if (useExactAlgorithmCheckBox.Checked == true)
            {
                warningLabel.Visible = false;
            }
            else
            {
                warningLabel.Visible = true;
            }
        }

        private void designerShipCheckBox_CheckedChanged(object sender, EventArgs e)
        {            
            //spaceLimitTextBox.Text = (MAX_HULLCAP - spaceRem).ToString();

            // If the checkbox is checked, set the value to that from the designer:
            if (designerShipCheckBox.Checked == true)
            {

                spaceLimiterUpDown.Value = (MAX_HULLCAP - spaceRem);
                if (leaveFuelRoomCheckbox.Checked == true)
                {
                    if (spaceLimiterUpDown.Value - TANK_SIZE >= 0)
                    {
                    spaceLimiterUpDown.Value -= TANK_SIZE;
                    }
                    else
                    {                    
                        spaceLimiterUpDown.Value = 0;
                    }
                    
                }
                spaceLimiterUpDown.Enabled = false;
            }
            if (designerShipCheckBox.Checked == false)
            {
                leaveFuelRoomCheckbox.Checked = false;
                spaceLimiterUpDown.Enabled = true;
            } 
        }

        private void addGunsToShipButton_Click(object sender, EventArgs e)
        {
            GetReturnValue();
        }

        public void GetReturnValue()
        {
            string gunNames = "";
            int i;

            for (i = 0; i < GUN_MOUNTS; i++)
            {
                try
                {
                    gunNames += weaponDataGrid.Rows[i].Cells[1].Value.ToString() + "|";
                }
                catch (Exception)
                {
                }
            }

            Result = gunNames;
            this.Close();
        }

       public string Result;

       private void goButton_Click(object sender, EventArgs e)
       {
           if (useExactAlgorithmCheckBox.Checked == true)
           {
               useExactAlgorithm();
           }
           else
           {
               useApproximateAlgorithm();
           }
       }

       private void leaveFuelRoomCheckbox_CheckedChanged(object sender, EventArgs e)
       {
           if (leaveFuelRoomCheckbox.Checked == true)
           {
               if (spaceLimiterUpDown.Value - TANK_SIZE >= 0)
               {
                   spaceLimiterUpDown.Value -= TANK_SIZE;
               }
               else
               {
                   spaceLimiterUpDown.Value = 0;
               }
           }
           else
           {
               spaceLimiterUpDown.Value += TANK_SIZE;
           }
       }
    }
}
